import { CoreConn } from "./CoreConn";

export abstract class IBroadcast {
    // socket: WebSocket;

    constructor() {
        // this.socket = socket;
    }

    send(str: string) {
        if (this.socket.readyState == 1) {
            this.socket.send(str);
        } else {
            console.log("socket 尚未連接");
        }
    }

    chainSend(str: string) {
        if (this.chainSocket.readyState == 1) {
            this.chainSocket.send(str);
        } else {
            console.log("socket 尚未連接");
        }
    }

    get socket(): WebSocket {
        return CoreConn.ins.mainSocket.socket;
    }

    get chainSocket(): WebSocket {
        return CoreConn.ins.subSocket.socket;
    }

    abstract subscribe(): void;

    abstract unSubscribe(): void;

    abstract handle(data?: any): void;
}
